import BScroll from "@better-scroll/core";
import { nextTick } from "vue";
let defaultOptions = {
  click: true,
};
export default function (
  dom: HTMLElement | HTMLElement[],
  targetCache,
  options
) {
  if (!Array.isArray(dom)) {
    dom = [dom];
  }
  nextTick(() => {
    if (targetCache.length > 0) {
      targetCache.map((item) => {
        item.refresh();
      });
    } else {
      (dom as Array<HTMLElement>).map((d, index) => {
        let item = new BScroll(d, {
          ...defaultOptions,
          ...options,
        });
        targetCache.push(item);
      });
    }
  });
}
